package qiniu

import (
	"context"
	"os"

	"github.com/qiniu/api.v7/auth/qbox"
	"github.com/qiniu/api.v7/storage"
)

var (
	accessKey = os.Getenv("QINIU_ACCESS_KEY")
	secretKey = os.Getenv("QINIU_SECRET_KEY")
	bucket    = os.Getenv("QINIU_TEST_BUCKET")
	io        = os.Getenv("QINIU_IO")
	up        = os.Getenv("QINIU_UP")
	api       = os.Getenv("QINIU_API")
	mac       = qbox.NewMac(accessKey, secretKey)
	putPolicy = storage.PutPolicy{Scope: bucket, Expires: 3600 * 24 * 365 * 100}
	upToken   = putPolicy.UploadToken(mac)

	zone = &storage.Zone{
		SrcUpHosts: []string{
			up,
		},
		ApiHost:   api,
		IovipHost: io,
	}
)

// Upload upload file to qiuniu
func Upload(key, localfile string) error {
	cfg := storage.Config{UseHTTPS: false, UseCdnDomains: false}
	cfg.Zone = zone
	formUploader := storage.NewFormUploader(&cfg)
	return formUploader.PutFile(context.Background(), &storage.PutRet{}, upToken, key, localfile, nil)
}

func Download(privateAccessURL string) error {
	return nil
}
